package com.fowo.api.syncAmazon.core.model;

/**
 * @fileName: SPRepuestParamModel
 * @Description: 代码目的，作用，如何工作
 * @Author: yyf
 * @Date: 2024/3/12 0012 14:00
 */

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 参数示例：
 * {
 *         "name":"SP campaigns report 7/5-7/10",
 *         "startDate":"2022-07-05",
 *         "endDate":"2022-07-10",
 *         "configuration":{
 *             "adProduct":"SPONSORED_PRODUCTS",
 *             "groupBy":["campaign","adGroup"],
 *             "columns":["adGroupId","campaignId", "impressions", "clicks", "cost", "purchases1d", "purchases7d", "purchases14d", "purchases30d","date"],
 *             "reportTypeId":"spCampaigns",
 *             "timeUnit":"DAILY",
 *             "format":"GZIP_JSON"
 *         }
 *     }
 */
@Data
public class SPRequestParamModel {
    private String name;
    private String startDate;
    private String endDate;
    private RequestConfigurationModel configuration;

    public String toJson() throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.writeValueAsString(this);
    }

    public void setStartDate(Date startDate) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String startDateTmp = format.format(startDate);
        this.startDate = startDateTmp;
    }

    public void setEndDate(Date endDate) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String endDateTmp = format.format(endDate);
        this.endDate = endDateTmp;
    }
}
